

package com.loong.loong.hik.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.loong.loong.common.core.util.R;
import com.loong.loong.common.log.annotation.SysLog;
import com.loong.loong.hik.entity.CdcUps;
import com.loong.loong.hik.service.CdcUpsService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.loong.loong.common.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ups表
 *
 * @author cs
 * @date 2023-04-13 15:07:05
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/cdcups" )
@Api(value = "cdcups", tags = "ups表管理")
public class CdcUpsController {

    private final  CdcUpsService cdcUpsService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param cdcUps ups表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('hik_cdcups_view')" )
    public R getCdcUpsPage(Page page, CdcUps cdcUps) {
        return R.ok(cdcUpsService.page(page, Wrappers.query(cdcUps)));
    }


    /**
     * 通过id查询ups表
     * @param indexCode id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{indexCode}" )
    @PreAuthorize("@pms.hasPermission('hik_cdcups_view')" )
    public R getById(@PathVariable("indexCode" ) String indexCode) {
        return R.ok(cdcUpsService.getById(indexCode));
    }

    /**
     * 新增ups表
     * @param cdcUps ups表
     * @return R
     */
    @ApiOperation(value = "新增ups表", notes = "新增ups表")
    @SysLog("新增ups表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('hik_cdcups_add')" )
    public R save(@RequestBody CdcUps cdcUps) {
        return R.ok(cdcUpsService.save(cdcUps));
    }

    /**
     * 修改ups表
     * @param cdcUps ups表
     * @return R
     */
    @ApiOperation(value = "修改ups表", notes = "修改ups表")
    @SysLog("修改ups表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('hik_cdcups_edit')" )
    public R updateById(@RequestBody CdcUps cdcUps) {
        return R.ok(cdcUpsService.updateById(cdcUps));
    }

    /**
     * 通过id删除ups表
     * @param indexCode id
     * @return R
     */
    @ApiOperation(value = "通过id删除ups表", notes = "通过id删除ups表")
    @SysLog("通过id删除ups表" )
    @DeleteMapping("/{indexCode}" )
    @PreAuthorize("@pms.hasPermission('hik_cdcups_del')" )
    public R removeById(@PathVariable String indexCode) {
        return R.ok(cdcUpsService.removeById(indexCode));
    }


    /**
     * 导出excel 表格
     * @param cdcUps 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('hik_cdcups_export')" )
    public List<CdcUps> export(CdcUps cdcUps) {
        return cdcUpsService.list(Wrappers.query(cdcUps));
    }
}
